<?php

namespace App\Models\Customer;

use App\Models\BaseModel;
use Illuminate\Database\Eloquent\Model;

/**
 * 客户等级模型类
 *
 * @author WangBin
 * @date 2021-09-24
 * @package App\Models
 */
class Grade extends BaseModel
{
    protected $table = 'b2c_customer_grade';
    protected $primaryKey = 'grade_id';

    /**
     * 获取等级列表（过滤器）
     *
     * @param array $filter
     * @return \Illuminate\Database\Eloquent\Builder|Model|object|null
     */
    public static function getByFilter(array $filter = [])
    {
        $grades = Grade::query();
        if(!empty($filter['grade_name'])) {
            $grades->where('grade_name', 'like', '%' . $filter['grade_name'] . '%');
        }
        $grades->orderByDesc('created_at');
        return $grades;
    }
}
